package com.trucle.vntraffic;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.EditText;
import android.util.Log;


public class FindPath extends Activity {
	// Initializing variables
	EditText inputSource;
	EditText inputDest;
	
	private RadioGroup radioBy;
	private RadioButton radioByButton;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.v("trucle","R.layout.input_find_path");
		setContentView(R.layout.input_find_path);		
		
		inputSource = (EditText) findViewById(R.id.source_path);
		inputDest = (EditText) findViewById(R.id.dest_path);
		radioBy = (RadioGroup) findViewById(R.id.radioBy);
		
		Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen);
		
		//Listening to button event
		btnNextScreen.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View arg0) {
				//Starting a new Intent
				
				int selectedId = radioBy.getCheckedRadioButtonId();
				 
				// find the radiobutton by returned id
			    radioByButton = (RadioButton) findViewById(selectedId);
	 
				Intent nextScreen = new Intent(getApplicationContext(), OutFindPath.class);
				
				String source =  inputSource.getText().toString();
				String destination = inputDest.getText().toString();
				
				StringBuffer st = new StringBuffer(source);
				source=source.replaceAll(" ","+");
				destination=destination.replaceAll(" ", "+");
				
				Log.v("trucle","source string = "+source);
				Log.v("trucle","destination string = "+destination);
				//Sending data to another Activity
				nextScreen.putExtra("source", source);
				nextScreen.putExtra("dest", destination);
				nextScreen.putExtra("goby", selectedId);
				
				// starting new activity
				startActivity(nextScreen);
				
			}
		});
	}
}
